package com.ds.infra.rpc.core.serializer;


import com.ds.infra.rpc.core.config.RpcConfig;

/**
 * 序列化工厂（根据配置选择实现）
 *
 * @author WeiShaoying
 */
public class SerializerFactory {

    private static Serializer serializer = new JacksonSerializer();

    //TODO 暂时写死
    public static void init(RpcConfig config) {
        switch (config.getSerializer()) {
            case JACKSON:
                serializer = new JacksonSerializer();
                break;
            // 可扩展其他序列化方式
            default:
                throw new UnsupportedOperationException();
        }
    }

    public static <T> byte[] serialize(T obj) {
        return serializer.serialize(obj);
    }

    public static <T> T deserialize(byte[] bytes, Class<T> clazz) {
        return serializer.deserialize(bytes, clazz);
    }
}
